<% include("../public/commonheader.html"){}%><!-- 配置文件 -->

<div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label for="L_caption" class="layui-form-label">
                            <span class="x-red">*</span>${L.caption}</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_caption" name="caption" value="${info.caption!}" lay-verify="required" autocomplete="off" class="layui-input"></div>
                        </div>
					<div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        ${L.privileges}
                    </label>
                    <table  class="layui-table layui-input-block">
                        <tbody>
                            <%for(parent in parents){%>
							<tr>
							  <td>
                                    <input type="checkbox" lay-skin="primary" lay-filter="father" title="${lists[parent].caption!}">
                                </td>
                                <td>
                                    <div class="layui-input-block">
									   <%if(lists[parent].child!=null){for(priv in lists[parent].child){%>
                                        <input name="privileges" lay-skin="primary" type="checkbox" title="${lists[priv].caption!}" value="${lists[priv].privi_id}" <%if(lists[priv].sel==1){%> checked="true"<%}%>/> 
										<%}}%>
                                    </div>
                                </td>
                            </tr>
							<%}%>
                        </tbody>
                    </table>
                </div>

                    <div class="layui-form-item">
					    <input type="hidden" name="role_id" value="${info.role_id}"/>
                        <button class="layui-btn" lay-filter="edit" lay-submit="">提交修改</button>
				    </div>
                </form>
            </div>
        </div>

<% include("../public/commonfooter.html"){}%>
<style type="text/css">
.layui-form-checkbox{width:128px;}
</style>
<script>
layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
				
           form.on('checkbox(father)', function(data){

            if(data.elem.checked){
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render(); 
            }else{
               $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();  
            }
          });

                //监听提交
                form.on('submit(edit)',
                function(data) {
					
					let privileges=[];
					$("input[name='privileges']:checked").each(function() { 
                         privileges.push($(this).val());
                       });
					$.post(jkas.url("/admin/roles/edit"),{role_id:data.field.role_id,caption:data.field.caption,privileges:privileges.toString()},function(result)
					{
                     if(200==result.code)
					 {
                    //发异步，把数据提交给php
                      layer.alert("修改成功", {
                        icon: 6
                      },
                      function() {
                        //关闭当前frame
                        Sca.close();

                        // 可以对父窗口进行刷新 
                        Sca.father_reload();
                      });
					  }
					  else
					  { layer.alert("操作失败 "+result.msg, {
                        icon: 5
                        });
					  }
				   },"json");
                    return false;
                });

            });
</script>
